/**
 * 
 */
package za.co.sindi.oauth.core.scanner.filter.impl;

import java.lang.annotation.Annotation;

import za.co.sindi.oauth.core.scanner.filter.TypeFilter;

/**
 * @author Buhake Sindi
 * @since 03 April 2012
 *
 */
public class AnnotationTypeFilter implements TypeFilter {
	
	private final Class<? extends Annotation> annotationClass;

	/**
	 * @param annotationClass
	 */
	public AnnotationTypeFilter(final Class<? extends Annotation> annotationClass) {
		super();
		if (annotationClass == null) {
			throw new IllegalArgumentException("Annotation class may not be null.");
		}
		
		this.annotationClass = annotationClass;
	}

	/* (non-Javadoc)
	 * @see com.neurologic.oauth.core.scanner.filter.TypeFilter#match(java.lang.Class)
	 */
	@Override
	public boolean match(Class<?> clazz) {
		// TODO Auto-generated method stub
		if (clazz == null) {
			throw new IllegalArgumentException("Class may not be null.");
		}
		
		if (Object.class.getName().equals(clazz.getName())) {
			return false;
		}
		
		return clazz.getAnnotation(annotationClass) != null;
	}
}
